﻿@using Abp.Authorization.Users
@using MPACore.Phonebook
@using MPACore.Phonebook.Web.Startup
@using MPACore.Phonebook.PhoneBooks.Dto
@model Abp.Application.Services.Dto.PagedResultDto<PersonListDto>
@{
    ViewBag.CurrentPageName = PageNames.Persons; // The menu item will be active for this page.
}
@section scripts
    {
    <environment names="Development">
        <script src="~/view-resources/Views/PhoneBook/Persons/Index.js" asp-append-version="true"></script>
    </environment>

    <environment names="Staging,Production">
        <script src="~/view-resources/Views/PhoneBook/Persons/Index.min.js" asp-append-version="true"></script>
    </environment>
}
<div class="row clearfix">
    <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
        <div class="card">
            <div class="header">
                <h2>
                    @L("Persons")
                </h2>
                <ul class="header-dropdown m-r--5">
                    <li class="dropdown">
                        <a href="javascript:void(0);" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
                            <i class="material-icons">more_vert</i>
                        </a>
                        <ul class="dropdown-menu pull-right">
                            <li><a id="RefreshButton" href="javascript:void(0);" class="waves-effect waves-block"><i class="material-icons">refresh</i>@L("Refresh")</a></li>
                        </ul>
                    </li>
                </ul>
            </div>
            <div class="body table-responsive">
                <table class="table">
                    <thead>
                        <tr>
                            <th>@L("Name")</th>
                            <th>@L("Email")</th>
                            <th>@L("Address")</th>
                            <th>@L("CreationTime")</th>
                            <th>@L("Actions")</th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach (var person in Model.Items)
                        {
                            <tr>
                                <td>@person.Name</td>
                                <td>@person.Email</td>
                                <td>@person.Address</td>
                                <td>@person.CreationTime.ToString("yyyy-MM-dd")</td>
                                <td class="dropdown">
                                    <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
                                        <i class="material-icons">menu</i>
                                    </a>
                                    <ul class="dropdown-menu pull-right">
                                        <li><a href="#" class="waves-effect waves-block edit-person" data-person-id="@person.Id" data-toggle="modal" data-target="#PersonCreateModal"><i class="material-icons">edit</i>@L("Edit")</a></li>
                                        <li><a href="#" class="waves-effect waves-block delete-person" data-person-id="@person.Id" data-person-name="@person.Name"><i class="material-icons">delete_sweep</i>@L("Delete")</a></li>
                                    </ul>
                                </td>
                            </tr>
                            if (person.PhoneNumbers.Count > 0)
                             {
                                 <tr>
                                     <th>电话类型</th>
                                     <th colspan="4">电话类型</th>
                                 </tr>
                                 foreach (var item in person.PhoneNumbers)
                                 {
                                     <tr>
                                         <td>@L(item.Type.ToString())</td>
                                         <td colspan="4">@item.Number</td>
                                     </tr>
                                 }
                             }
                        }
                    </tbody>
                </table>
                <button type="button" class="btn btn-primary btn-circle waves-effect waves-circle waves-float pull-right" data-toggle="modal" data-target="#PersonCreateModal">
                    <i class="material-icons">add</i>
                </button>
            </div>
        </div>
    </div>
</div>

<div class="modal fade" id="PersonCreateModal" tabindex="-1" role="dialog" aria-labelledby="PersonCreateModalLabel" data-backdrop="static">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title">
                    <span>@L("CreateNewPerson")</span>
                </h4>
            </div>
            <div class="modal-body">
                <form name="personCreateForm" role="form" novalidate class="form-validation">                   
                    <div class="tab-content">
                        <div role="tabpanel" class="tab-pane animated fadeIn active" id="create-person-details">
                            <div class="row clearfix" style="margin-top:10px;">
                                <div class="col-sm-12">
                                    <div class="form-group form-float">
                                        <div class="form-line">
                                            <input type="hidden" name="Id" />
                                            <input class="form-control" type="text" name="Name" required maxlength="@PhonebookConsts.MaxNameLength" minlength="2">
                                            <label class="form-label">@L("Name")</label>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="row clearfix" style="margin-top:10px;">
                                <div class="col-sm-12">
                                    <div class="form-group form-float">
                                        <div class="form-line">
                                            <input class="form-control" type="email" name="Email" maxlength="@PhonebookConsts.MaxEmailLength">
                                            <label class="form-label">@L("Email")</label>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="row clearfix" style="margin-top:10px;">
                                <div class="col-sm-12">
                                    <div class="form-group form-float">
                                        <label>@L("PhoneNumberType")</label>
                                        <select name="PhoneNumberType" class="form-control selectpicker">
                                            <option value="1">@L("Mobile")</option>
                                            <option value="2">@L("Home")</option>
                                            <option value="3">@L("Company")</option>
                                        </select>
                                    </div>
                                </div>
                            </div>
                            <div class="row clearfix" style="margin-top:10px;">
                                <div class="col-sm-12">
                                    <div class="form-group form-float">
                                        <div class="form-line">
                                            <input class="form-control" type="tel" name="PhoneNumber" required maxlength="@PhonebookConsts.MaxPhoneNumberLength">
                                            <label class="form-label">@L("PhoneNumber")</label>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="row clearfix" style="margin-top:10px;">
                                <div class="col-sm-12">
                                    <div class="form-group form-float">
                                        <div class="form-line">
                                            <input class="form-control" type="text" name="Address" maxlength="@PhonebookConsts.MaxAddreLength">
                                            <label class="form-label">@L("Address")</label>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default waves-effect" data-dismiss="modal">@L("Cancel")</button>
                        <button type="submit" class="btn btn-primary waves-effect">@L("Save")</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>